package com.yserp.project.erp.order.purchorder.controller;

import com.yserp.common.utils.poi.ExcelUtil;
import com.yserp.framework.aspectj.lang.annotation.Log;
import com.yserp.framework.aspectj.lang.enums.BusinessType;
import com.yserp.framework.web.controller.BaseController;
import com.yserp.framework.web.domain.AjaxResult;
import com.yserp.framework.web.page.TableDataInfo;
import com.yserp.project.erp.order.purchorder.domain.PurchOrderItem;
import com.yserp.project.erp.order.purchorder.service.IPurchOrderItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 采购订单子Controller
 * 
 * @author yserp
 * @date 2022-08-02
 */
@Controller
@RequestMapping("/order/purchorder/item")
public class PurchOrderItemController extends BaseController
{
    private String prefix = "erp/order/purchorder";

    @Autowired
    private IPurchOrderItemService purchOrderItemService;

    @RequiresPermissions("order:purchorder:view")
    @GetMapping()
    public String purchorder()
    {
        return prefix + "/purchorder";
    }

    /**
     * 查询采购订单子列表
     */
    @RequiresPermissions("order:purchorder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PurchOrderItem purchOrderItem)
    {
        startPage();
        List<PurchOrderItem> list = purchOrderItemService.selectPurchOrderItemList(purchOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出采购订单子列表
     */
    @RequiresPermissions("order:purchorder:export")
    @Log(title = "采购订单子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PurchOrderItem purchOrderItem)
    {
        List<PurchOrderItem> list = purchOrderItemService.selectPurchOrderItemList(purchOrderItem);
        ExcelUtil<PurchOrderItem> util = new ExcelUtil<PurchOrderItem>(PurchOrderItem.class);
        return util.exportExcel(list, "采购订单子数据");
    }

    /**
     * 查询子表列表
     */
    @PostMapping("/ajaxList")
    @ResponseBody
    public AjaxResult ajaxList(PurchOrderItem purchOrderItem) {
        List<PurchOrderItem> list = purchOrderItemService.selectPurchOrderItemList(purchOrderItem);
        return AjaxResult.success(list);
    }


}
